package com.yzy.javastring;

public class Test {

    public static void main(String[] args) {

/*
        String s1 = "123";
        String s2 = new String("123");
        String s3 = new String("456");
        String s4 = "456";

        String s5 = s2.intern();
        String s6 = s3.intern();

        System.out.println(s1 == s2);
        System.out.println(s1 == s5);
        System.out.println(s2 == s5);

        System.out.println(s3 == s4);
        System.out.println(s3 == s6);
        System.out.println(s6 == s4);
*/


       String s7="abc"+"def";
       String s8= new String(s7);
       if (s7.equals(s8))System.out.println("==succeded");
       if(s7 == s8) System.out.println("．equals( )succeded");


       //***  判断一个String对象地址指向的是否是常量池的地址，可用  s == s.intern() 来判断，因为 intern方法总是返回常量池中对象的地址
       String s1 = "a";
       String s4 = "ab";
       String s2 = s1 + "b";    //
       String s3 = "a" + "b";   // 这个等价于 s3 = "ab";  实际s3指向的就是常量池中 ab 的地址,原因是因为 s3 == s3.intern()为 true
       System.out.println(s2 == s3);    // false
       System.out.println(s2 == s4);    // false
       System.out.println(s3 == s4);    // true
       System.out.println(s3 == s3.intern());   // true
       System.out.println(s2 == s2.intern());   // false


    }

}
